/////////////////////////////////////////////////////////////////////////////
// Defines interfaces for thread functions.
//
// Version 1.0 - 15 june 2007
//
// Copyright (c) 2007 by FlexByte Software (http://flexbyte.com)
// All rights reserved.
//
// You may use the source code in any product (freeware, commercial, etc.). 
// You may modify the source code as you want except 
// you cannot modify the copyright details at the top of each module.
// If you have a web site or blog give a link to our web site, flexbyte.com
/////////////////////////////////////////////////////////////////////////////
#ifndef __FLEX_THREAD_H
#define __FLEX_THREAD_H
#include <vcl.h>
/////////////////////////////////////////////////////////////////////////////
struct IExecutable
{
	virtual void Execute()	= 0;
	virtual void Break()	= 0;
};
typedef struct tagTHREADNAME_INFO
{
   DWORD dwType; // Must be 0x1000.
   LPCSTR szName; // Pointer to name (in user addr space).
   DWORD dwThreadID; // Thread ID (-1=caller thread).
   DWORD dwFlags; // Reserved for future use, must be zero.
} THREADNAME_INFO;

/////////////////////////////////////////////////////////////////////////////
class CFlexThread
{
// Constructor/Destructor
public:
	CFlexThread();
	virtual ~CFlexThread(void);

// Attributes
	DWORD	GetThreadId() const;

// Implementation
	void	Execute(IExecutable * pExec);
	void	Exit();
	void	Wait(DWORD dwTimeout = INFINITE);
	void	MsgWait(DWORD dwTimeout = INFINITE);


private:
	static DWORD	_Thread(LPVOID param);

// Members
private:
	HANDLE			m_hThread;
	DWORD			m_dwThreadId;
	IExecutable *	m_pExec;
};
/////////////////////////////////////////////////////////////////////////////
inline DWORD CFlexThread::GetThreadId() const
{
	return m_dwThreadId;
}
/////////////////////////////////////////////////////////////////////////////
#endif // __FLEX_THREAD_H
